# -*- coding: utf-8 -*-
# @Time        :2025/3/8 15:35
# @Author      :文刀水寿
# @File        : 22_爬虫_解析_jsonpath解析淘票票.py
"""
 @Description :
"""
import json
import urllib.request
import jsonpath

url = 'https://www.taopiaopiao.com/cityAction.json?activityId&_ksTS=1741419392357_117&jsoncallback=jsonp118&action=cityAction&n_s=new&event_submit_doGetAllRegion=true'

headers = {
    # ':authority':'www.taopiaopiao.com',
    # ':method':'GET',
    # ':path':'/cityAction.json?activityId&_ksTS=1741419392357_117&jsoncallback=jsonp118&action=cityAction&n_s=new&event_submit_doGetAllRegion=true',
    # ':scheme':'https',
    'accept': 'text/javascript,application/javascript,application/ecmascript,application/x-ecmascript,*/*;q=0.01',
    # 'accept-encoding':'gzip,deflate,br,zstd',
    'accept-language': 'zh-CN,zh;q=0.9',
    'bx-v': '2.5.28',
    'cookie': 'cna=NOFSIGveERkCAXAuSkJOwaWQ;xlly_s=1;tb_city=110100;tb_cityName="sbG+qQ==";dnk=;t=0f1b81d4875f263a1ccef0434610da82;lgc=;sn=;_tb_token_=3beb068e0b63b;cookie2=135d1e7097d752b7c7b54a89c5abc730;_nk_=;mtop_partitioned_detect=1;_m_h5_tk=f5513ceafd6751729bdf39b3d894d85e_1741427981824;_m_h5_tk_enc=bcc5740c3bed2a30a8cc23084fdabd50;tfstk=guOqhsg_-jhVJqOqjafaU5TnUx1A6smBSCs1SFYGlijDlFbG_3YMlqCf1f5wqgOfcE1D_h8e0KNfiCtw_HsWf5TXfrpJAeVXGxC__sCOsDiIOXTXk1CiipDOWiLkyN05oIQH5qfOsDi7kipFL1Kdw7Z9n8bl2N7gn5xGETbNqoqMjiXuqw7dsGxMjbYllNVgIZbcE47OqGfGshYopKKvXk_hnV5o6h8YPZBVxEjz_EdPotyvogPgsQJV3MVN45VMaZ872jLaTAsHpi6CU3c7g18l7nsWxXVPZ9Jp5N-qgSfXELdAGQiUJt-Nc9A5UbqPzQ8BKaLrL48y_iWHiTz_9ECVShXweDPCus9PLIJxWuYDAiJhMFaEcUWeU9QlEPycGpTB69AmgkI5pN-fVHc3a_XG47qOrqr66KrgQtbRzMgrzq7u-nllEkWTBRBlKaSIkO2TBtbRzMgrzReOHWbPAqBG.;ariaDefaultTheme=undefined;isg=BMrKoDTqmc6DLxVid0a6sbbJG7Bsu04V-cWv9lQDd52oB2jBPEovJTExE3Xb88at',
    'priority': 'u=1,i',
    'referer': 'https://www.taopiaopiao.com/?tbpm=3',
    # 'sec-ch-ua':'Not(A':'Brand;v="99","MicrosoftEdge";v="133","Chromium";v="133"',
    'sec-ch-ua-mobile': '?1',
    'sec-ch-ua-platform': '"Android"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0(Linux;Android6.0;Nexus5Build/MRA58N)AppleWebKit/537.36(KHTML,likeGecko)Chrome/133.0.0.0MobileSafari/537.36Edg/133.0.0.0',
    'x-requested-with': 'XMLHttpRequest'
}

request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf8')
content = content.split('(')[1].split(')')[0]

with open("22_爬虫_解析_jsonpath解析淘票票.json", 'w', encoding='utf8') as fp:
    fp.write(content)

obj = json.load(open('22_爬虫_解析_jsonpath解析淘票票.json', 'r', encoding='utf8'))

regionName_list = jsonpath.jsonpath(obj, '$.returnValue..regionName')

print(regionName_list)
